<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.net.URLEncoder" %>
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
<%@taglib uri="/WEB-INF/tlds/framework.tld" prefix="framework"%>
<%
String requestURL = request.getRequestURL().toString();
String contextPath = request.getContextPath();
int contextPathIndex = requestURL.indexOf(contextPath);
%>
<%!
String getRequestURI(HttpServletRequest request){
	String uri = (String)request.getAttribute(whf.framework.web.Constants.STRUTS_PATH);
	if(uri == null){
		uri = request.getRequestURI();
	} else if(!uri.endsWith(".do")){
		uri += ".do";
	}
	uri = request.getContextPath() + uri;
	uri += "?";
	String queryString = request.getQueryString();
	if(queryString != null){
		uri += queryString;
	} else {
		uri += "!=0";
	}
	return uri;
}
%>
<script>
var globalContextPath;
var globalRequestPath;
globalContextPath= '<%= request.getContextPath()%>';
globalRequestPath='<%= requestURL.substring(0, contextPathIndex + contextPath.length()) %>';
</script>
<link href="<%= request.getContextPath()%>/css/default.css" rel="stylesheet" type="text/css">
<link href="<%= request.getContextPath()%>/css/table.css" rel="stylesheet" type="text/css">

<script language="jscript" src="<%= request.getContextPath()%>/scripts/htc/global.js"></script>
<script language="jscript" src="<%= request.getContextPath()%>/scripts/prototype-1.4.0.js"></script>
<SCRIPT language="JavaScript" src="<%=request.getContextPath()%>/scripts/jscalendar/calendar.js" type="text/javascript"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=request.getContextPath()%>/scripts/tapestry_calendar.js" type="text/javascript"></SCRIPT>

<script language="jscript" src="<%= request.getContextPath()%>/library/js/common.js"></script>

<style>
.selectInput
{
    BORDER-RIGHT: #4587C4 0px solid;
    BORDER-TOP: #4587C4 0px solid;
    FONT-SIZE: 9pt;
    BORDER-LEFT: #4587C4 0px solid;
    COLOR: #0000A0;
    BORDER-BOTTOM: #6C6D86 1px solid;
    FONT-FAMILY: Arial,宋体;
	SIZE:10;
    behavior: url('<%= request.getContextPath()%>/scripts/htc/myselect.htc');
}
.commonInput
{
    BORDER-RIGHT: #4587C4 0px solid;
    BORDER-TOP: #4587C4 0px solid;
    FONT-SIZE: 9pt;
    BORDER-LEFT: #4587C4 0px solid;
    COLOR: #0000A0;
    BORDER-BOTTOM: #6C6D86 1px solid;
    FONT-FAMILY: Arial,宋体;
}
BODY{
	scrollbar-face-color: #DEE3E7;
	scrollbar-highlight-color: #D1D7DC;
	scrollbar-shadow-color: #98AAB1;
	scrollbar-3dlight-color: #ffffff;
	scrollbar-arrow-color: #006699;
	scrollbar-track-color: #EFEFEF;
	scrollbar-darkshadow-color: #EFEFEF;
	margin-left:0px;
	margin-top:0px;
	margin-right:0px;
	margin-bottom:0px;
	overflow-x:auto;
	overflow-y:auto;
	font-size:9pt;
	FONT-FAMILY: Arial,宋体;
	text-align: left;
}
</STYLE>

<script language="javascript">
var screenWidth = screen.width;
var screenHeight = screen.height;

function openCustomizeColumnsWindow(tableId){
	window.open("<%= request.getContextPath() %>/common/customize_columns.jsp?tableId="+tableId,null, 
		"height=400,width=300,top="+((screenHeight - 400) / 2)+",left="+((screenWidth - 300) / 2));
}

function openDesignViewWindow(viewId, type) {
	if(type == 'view')
		window.open("<%= request.getContextPath() %>/framework/meta/View.do?webMethod=prepareUpdate&id="+viewId);
	else
		window.open("<%= request.getContextPath() %>/framework/meta/Object.do?webMethod=prepareUpdate&id="+viewId);
}

function openWindow(url, properties){
	window.open("<%= request.getContextPath() %>/"+url, null, properties);
}

// calendar function
var tapestry_calendar = null;
function showDatetimeWindow(controlId, datatype){
	var obj = document.getElementById(controlId);
	if(true){
		var screenX = window.event.screenX + 20;
		var screenY =window.event.screenY + 10;
		var args =new Object;
		args.datatype=datatype;
		args.value =obj.value;
		var rst=window.showModalDialog(globalContextPath+"/library/js/date.jsp", args, "dialogWidth:250px; dialogHeight:260px; status:0");
		if(rst)	obj.value=rst;
	} else {
		var obj = document.getElementById(controlId);
		if(null == tapestry_calendar){
			tapestry_calendar = new Calendar(new Date());
			tapestry_calendar.create();	
		}
		tapestry_calendar.onchange = function() {
			tapestry_calendar.setFormat("yyyy-MM-dd");
			obj.value  = tapestry_calendar.formatDate();
		}
		tapestry_calendar.toggle(obj);
	}
}

function openReportPreview(tableUniqueID, totalRowCount){
	if(totalRowCount > 1000){
		if(!confirm('There has more than 1000 Objects, continue?')){
			return;
		}
	}
	var sh = screen.height - 100;
	var sw = screen.width - 100;
	window.open("<%= request.getContextPath() %>/common/reports/appletview.jsp?url=<%= URLEncoder.encode(getRequestURI(request)+"&e_=true&et_=applet&en_=Report.applet&reportName=Applet","UTF-8") %>", null,
		'height='+sh+', width='+sw+', toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
}
function openReportExport2Pdf(tableUniqueID, totalRowCount){
	if(totalRowCount > 1000){
		if(!confirm('There has more than 1000 Objects, continue?')){
			return;
		}
	}
	window.location="<%= getRequestURI(request) %>&e_=true&et_=pdf&en_=Report.pdf";
}
function openReportExport2Xls(tableUniqueID, totalRowCount){
	if(totalRowCount > 1000){
		if(!confirm('There has more than 1000 Objects, continue?')){
			return;
		}
	}
	window.location="<%= getRequestURI(request) %>&e_=true&et_=xls&en_=Report.xls";
}
//
function tableTagRowOnMouseOver(tableRow, className){
	if(!tableRow.getAttribute("initClassName"))
		tableRow.setAttribute("initClassName",tableRow.className);
	var tbody = tableRow.parentElement;
	var selectedRow = tbody.getAttribute("selectedRow");
	if(selectedRow != tableRow)
		tableRow.className = className;
}

function tableTagRowOnMouseOut(tableRow, className){
	if(!tableRow.getAttribute("initClassName"))
		tableRow.setAttribute("initClassName",tableRow.className);
	var tbody = tableRow.parentElement;
	var selectedRow = tbody.getAttribute("selectedRow");
	if(selectedRow != tableRow)
		tableRow.className = className;
}

function tableTagRowOnClick(tableRow){
	var tbody = tableRow.parentElement;
	var selectedRow = tbody.getAttribute("selectedRow");
	if(selectedRow){
		selectedRow.className = selectedRow.getAttribute("initClassName");
	}
	
	tbody.setAttribute("selectedRow", tableRow);
	//
	tableRow.className = "whf_table_body_row_selected";
}

function changeAllSelections(src) {
	if(!src) src = event.srcElement;
	var checked = src.checked;
	var table = src.parentElement;
	var headerRow = src.parentElement;
	while(table.tagName != "TABLE") {
		table = table.parentElement;
		if(table.tagName == "TR"){
			headerRow = table;
		}
		if(!table) return;
	}
	var rows = table.rows;
	for(var i=0; i<rows.length; i++) {
		var row = rows[i];
		if(row == headerRow) 
			continue;
		for(var j=0; j< row.cells.length; j++) {
			var cell = row.cells[j];
			var children = cell.childNodes;
			for(var k=0; k < children.length; k++){
				if(children[k].tagName == "INPUT" && children[k].type.toUpperCase() == "CHECKBOX") {
					children[k].checked = src.checked;
					break;
				}
			}
		}
	}
}
</script>
<logic:present name="STRUTS-FORMNAME">

<script language="jscript">
function currentForm(){
	formName = '<framework:attr source="STRUTS-FORMNAME" />';
	return document.forms[formName];
}
function submitForm(nextMethod, formTarget){
	if(!formTarget) formTarget = "_self";
	<framework:attr source="STRUTS-FORMNAME" />.setAttribute("target", formTarget);
	if(nextMethod == "delete" || nextMethod == "remove"){
		if(confirm("<framework:attr attr="form.confirm_delete" />")){
			<framework:attr source="STRUTS-FORMNAME" />("webMethod").value=nextMethod;
			window.event.srcElement.disabled=true;
			<framework:attr source="STRUTS-FORMNAME" />.submit();
		}
	}else{
		<framework:attr source="STRUTS-FORMNAME" />("webMethod").value=nextMethod;
		if(window.event.srcElement.tagName == 'BUTTON')
			window.event.srcElement.disabled=true;
		<framework:attr source="STRUTS-FORMNAME" />.submit();
	}
}
function getSelectedIds(namePrefix){
	var idName = "id";
	if(namePrefix) idName = namePrefix + idName;
	var eles = document.getElementsByName(idName);
	var res = "";
	for(i =0;i<eles.length; i++){
		if(eles[i].checked){
			if(res == ""){
				res = eles[i].value;
			} else {
				res =","+eles[i].value;
			}
		}
	}
	return res;
}

function selectionMoreThanOne(namePrefix){
	var idName = "id";
	if(namePrefix) idName = namePrefix + idName;
	var eles = document.getElementsByName(idName);
	if(eles.length == 0){
		alert('<framework:attr attr="form.selection_none" />');
		return false;
	}
	for(i = 0; i < eles.length; i++){
		if(eles[i].checked){
			return true;
		}
	}
	alert('<framework:attr attr="form.selection_more_than_one" />');
	return false;
}

function selectionOnlyOne(namePrefix){
	var idName = "id";
	if(namePrefix) idName = namePrefix + idName;
	var eles = document.getElementsByName(idName);
	if(eles.length == 0){
		alert('<framework:attr attr="form.selection_none" />');
		return false;
	}
	var count = 0;
	for(i = 0; i < eles.length; i++){
		if(eles[i].checked){
			count ++;
		}
	}
	if(count != 1){
		alert('<framework:attr attr="form.selection_only_one" />');
		return false;
	} else {
		return true;
	}
}

function enumOptionSelect(objId, objName){
	var ele = document.getElementById(objId);
	if(ele == null) return;
	ele.value = '';
	var eles = document.getElementsByName(objName+"_Option");
	for(i = 0; i < eles.length; i++){
		if(eles[i].checked){
			if(ele.value == ''){
				ele.value=eles[i].value;
			} else {
				ele.value=ele.value+","+eles[i].value;
			}
		}
	}
}

function checkFormValidation(form){
	var msg = "";
	var inputs = form.tags("input");
	for(i=0; i< inputs.length; i++){
		if(inputs[i].type.toLowerCase() == 'hidden' || inputs[i].style.display == 'none') continue;
		var value = inputs[i].value;
		var name = inputs[i].name;
		if(name.substring(0, 1) == "_"){
			name = name.substring(1, name.length );
		}
		if(name.length > 4){
			if(name.substring(name.length - 4, name.length) == "BOID"){
				name = name.substring(0, name.length - 4);
			}
		}
		if(name == "") continue;
		var title = document.getElementById("title_"+name).innerText;
		if(title.substring(title.length - 1, title.length) == "*"){
			title = title.substring(0, title.length - 1);
		}
		var msgspan = document.getElementById(name + "msg");
		if(msgspan)
			msgspan.innerText = "";
		var inputmsg = "";
		if(inputs[i].required == 'true'){
			if(value == ''){
				inputmsg = "“"+title+"”不能空！";
				msgspan.innerText = inputmsg;
				if(msg != "") msg += "\n";
				msg += inputmsg;
			}
		}
		//长度检查
		var dataType = inputs[i].dataType;
		var maxLength = inputs[i].maxLength;
		try{
			if(maxLength != "" && dataType.toLowerCase() == "string"){
				var length = value.length;
				if(length > parseInt(maxLength)){
					inputmsg = title + "最大长度为：" + maxLength;
					msgspan.innerText = inputmsg;
					if(msg != "") msg += "\n";
					msg += inputmsg;
				}
			}
		}catch(e){
		}
		//范围检查
		var maxValue = inputs[i].maxValue;
		var minValue = inputs[i].minValue;
		if(maxValue && maxValue != ""){
			if(dataType == "number"){
			}
		}
	}
	return msg;
}
</script>
</logic:present>